home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
diskutil
/
serial.zoo
/
serial.pas
< prev
Wrap
Pascal/Delphi Source File
|
1990-08-15
|
5KB
|
160 lines
program serial;
uses crt,dos;
VAR
bad_dev : boolean;
drv,inp : char;
regs : registers;
bios_id : byte;
boot : array[0..511] of byte;
bios_err: boolean;
err_count : byte;
old_ser : longint;
procedure dreset;
{resets the drive in the regs record, saves the relevant parameters...}
var temp:word;
begin
temp:=regs.ax;
regs.ax:=0; {reset function}
intr(19,regs);
regs.ax:=temp;
end;
procedure rw_boot(fn:byte);
{reads/writes the bootsector...}
begin
bios_id:=ord(drv)-ord('A');
bios_err:=true;
repeat
err_count:=0;
while (err_count<10) and bios_err do
begin
{Now lets set up some registers...}
regs.ah:=fn; {read/write}
regs.es:=seg(boot); {Segment of storage}
regs.bx:=ofs(boot); {Offset of storage}
regs.dl:=bios_id; {Drive ID}
regs.dh:=0; {side 0}
regs.ch:=0; {track 0}
regs.cl:=1; {fisrt sector.. STUPID!}
regs.al:=1; {read 1 sector}
intr(19,regs); {Call BIOS}
if (regs.flags and Fcarry)=1 then
begin
err_count:=err_count+1;
dreset;
delay(100) {hang on a bit}
end
else bios_err:=false {it worked}
end;
if bios_err then
begin
Writeln;
writeln('BIOS error. Hit <R> to retry, or <CR> to exit');
repeat
inp:=upcase(readkey)
until (inp='R') or (inp=chr(13));
if inp=chr(13) then halt(0)
end;
until not(bios_err)
end;
procedure WriteHexDigit(d: integer);
begin
if d < 10 then begin
Write(d)
end
else begin
Write(Chr(d - 10 + Ord('A')))
end
end;
procedure doit;
begin
Writeln;
writeln('Enter the drive identifier for the disk to be initialised, or <CR> to exit.');
write(' -> ');
bad_dev:=true;
drv:=' ';
while bad_dev do
begin
repeat
drv:=upcase(readkey);
if drv=chr(13) then halt(0);
until (drv>='A') and (drv<='Z');
writeln(drv);
{Now call IOCTL() to suss out the drive...}
regs.ah:=68; {ioctl}
regs.al:=8; {subfunction 8, is device removable?}
{This seems a reasonable test for floppy...}
{It will certainly save grief on HD's}
regs.bl:=1+ord(drv)-ord('A');
{And a device number...}
msdos(regs);
case regs.ax of
0 : bad_dev:=false;
{Ok, it's removable}
1 : begin
write('Device ',drv,': is non-removable.');
{Obviously not}
write(' -> ');
end;
15 : begin
writeln('Device ',drv,': does not exist.');
write(' -> ');
{Invalid drive}
end;
end;
end;
writeln('Reading bootsector from device ',drv,':');
rw_boot(2); {Read the bootsector}
write('Serial was :');
writehexdigit(boot[8] div 16);
writehexdigit(boot[8] mod 16);
writehexdigit(boot[9] div 16);
writehexdigit(boot[9] mod 16);
writehexdigit(boot[10] div 16);
writehexdigit(boot[10] mod 16);
writeln;
writeln('Bootsector read, modifying...');
randomize;
boot[8]:=random(255);
boot[9]:=random(255);
boot[10]:=random(255);
writeln('Writing bootsector to device ',drv,':');
rw_boot(3); {Write the bootsector}
write('Serial is :');
writehexdigit(boot[8] div 16);
writehexdigit(boot[8] mod 16);
writehexdigit(boot[9] div 16);
writehexdigit(boot[9] mod 16);
writehexdigit(boot[10] div 16);
writehexdigit(boot[10] mod 16);
writeln;
end;
begin {main}
writeln;
writeln(' Atari ST disk serialiser for MS-DOS.');
writeln(' (C) and freeware, 1990 by Michael Smith.');
writeln(' ma892224@lux.sait.edu.au.');
repeat
doit;
until false;
end.ə